package com.min.uitest.ui.customcp

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.google.accompanist.coil.rememberCoilPainter
import com.min.uitest.bean.ImageBean


var list = mutableListOf<ImageBean>();

@Composable
fun showList(navController: NavController) {
    list.add(
        ImageBean(
            "小明",
            14,
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fattach.bbs.miui.com%2Fforum%2F201303%2F16%2F173710lvx470i4348z6i6z.jpg&refer=http%3A%2F%2Fattach.bbs.miui.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627179561&t=b8c816196bfb567804fb2af2fbae968b"
        )
    )
    list.add(
        ImageBean(
            "香蕉",
            14,
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.168mh.com%2Fwp-content%2Fuploads%2F2019%2F06%2F167010e15a86a51.jpg&refer=http%3A%2F%2Fwww.168mh.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627192931&t=e4e0c237b17147493bd3ae7c571d4221"
        )
    )
    list.add(
        ImageBean(
            "苹果",
            14,
            "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Ftu1.whhost.net%2Fuploads%2F20181031%2F23%2F1541001504-McOpEUKSIR.jpg&refer=http%3A%2F%2Ftu1.whhost.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627192931&t=acdfbc283e35efd6b18a7be55476fa4c"
        )
    )
    Column() {
        list.forEach() {
            ImageBeanItem(it)
        }
    }
}
//https://google.github.io/accompanist/
//https://google.github.io/accompanist/coil/
//https://oss.sonatype.org/content/repositories/snapshots/com/google/accompanist/
@Composable
fun ImageBeanItem(item: ImageBean) {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .border(1.dp, Color(0x666666), shape = RoundedCornerShape(4.dp)),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        Image(
            painter = rememberCoilPainter(request = item.imageUrl),
            contentDescription = "icon",
            modifier = Modifier.clip(CircleShape)
                .padding(12.dp,10.dp,12.dp,10.dp)
                .size(80.dp,80.dp)
        )
        Column(modifier = Modifier.weight(1f)) {
            Text(text = "姓名${item.name}", fontSize = 16.sp, color = Color.Black)
            Text(text = "年龄:${item.age}", fontSize = 14.sp, color = Color(0xFF333333))
        }

    }
}

